import { createTransport } from "nodemailer";
import { reginCode,adminLoginCode } from './mailTemplate/index'
import { MAIL_CONFIG,SEND_NAME } from '../server.config'
const smtpTransport = createTransport(MAIL_CONFIG)

export const sentMail = ({to,title,text,html}) =>{
  return smtpTransport.sendMail({
    from: `${SEND_NAME}`,
    to,
    subject:title,
    text,
    html,
  })
}

export const reginCodeMail = ({to,time,code}) => {
  return sentMail({
    to,
    title:'SRC-验证码',
    html:reginCode({code,time,username:to})
  })
}

export const sendAdminCode = ({to,code}) => {
  return sentMail({
    to,
    title:'管理员密码',
    html:adminLoginCode({code,username:to})
  })
}